import Vue from 'vue'
import Vuex from 'vuex'
import { getItem,setItem } from '@/utils/storage'
Vue.use(Vuex)
const TOKEN_KEY = 'TOUTIAO_USER'
export default new Vuex.Store({
  state: {
    // 用户的token
    user: getItem(TOKEN_KEY) || {}
  },
  mutations: {
    // 设置token
    setUser(state,data){
      // 设置给state
      state.user = data
      // 存储到本地
      setItem(TOKEN_KEY,data)
    }
  },
  // 建立快捷访问
  getters:{
    token:state=>state.user.token
  },
  actions: {
  },
  modules: {
  }
})
